﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Test_2D
{
    public partial class CanvasSize : Form
    {
        public CanvasSize(Canvas _cvs)
        {
            InitializeComponent();
            cvs = _cvs;
            init();
        }

        private void init()
        {
            textBox1.Text = cvs.Size.Width.ToString();
            textBox2.Text = cvs.Size.Height.ToString();
            pictureBox1.BackColor = cvs.Color;
        }

        Canvas cvs;
        public Canvas Canvas
        {
            get { return cvs; }
        }

        bool change = false;
        /// <summary>
        /// 获取是否按下了确定按钮
        /// </summary>
        public bool Change
        {
            get { return change; }
        }

        //取消
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //确定
        private void button2_Click(object sender, EventArgs e)
        {
            if (MyFunc.isDigit(textBox1.Text) && MyFunc.isDigit(textBox2.Text))
            {
                this.cvs = new Canvas(new Size(int.Parse(textBox1.Text), int.Parse(textBox2.Text)), pictureBox1.BackColor);
                this.change = true;     //设定已更新画布
                this.Close();
            }
            else
                MessageBox.Show("数据输入不合法");

        }
        //更改颜色
        private void button3_Click(object sender, EventArgs e)
        {
            colorDialog1.AllowFullOpen = true;
            colorDialog1.ShowHelp = true;
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.BackColor = colorDialog1.Color;
            } 
        }
        
    }
}
